package com.atguigu.serviceedu.controller.site;

import com.atguigu.dto.CourseDto;
import com.atguigu.serviceedu.entity.EduCourse;
import com.atguigu.serviceedu.entity.vo.ChapterVO;
import com.atguigu.serviceedu.entity.vo.SiteCourseQueryVO;
import com.atguigu.serviceedu.entity.vo.SiteCourseVO;
import com.atguigu.serviceedu.service.EduChapterService;
import com.atguigu.serviceedu.service.EduCourseService;
import com.atguigu.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/site/educourse")
public class SiteCourseController {
    @Autowired
    private EduCourseService eduCourseService;
    @Autowired
    private EduChapterService eduChapterService;

    @PostMapping("/getCourseByCondition")
    public ResultVO getCourseByCondition(@RequestBody SiteCourseQueryVO siteCourseQueryVO) {
        List<EduCourse> courseList = eduCourseService.getSiteCourseByCondition(siteCourseQueryVO);
        return ResultVO.ok().Msg("按条件查询课程成功").Data("courseList", courseList);
    }

    @GetMapping("/getSiteCourseVOById/{id}")
    public ResultVO getSiteCourseVOById(@PathVariable("id") String id) {
        List<ChapterVO> chapterVOList = eduChapterService.queryNestByCourseId(id);
        SiteCourseVO siteCourseVO = eduCourseService.querySiteCourseVOById(id);
        return ResultVO.ok().Msg("查询课程siteCourseVO和chapterVOList成功")
                .Data("siteCourseVO", siteCourseVO)
                .Data("chapterVOList", chapterVOList);
    }
    @GetMapping("/inner/getCourseDtoById/{id}")
    public CourseDto getCourseDtoById(@PathVariable(value = "id")String id){
        CourseDto courseDto = eduCourseService.queryCourseDtoById(id);
        return courseDto;
    }
}
